package com.example.demo.service.impl;

import com.codingapi.tx.annotation.ITxTransaction;
import com.codingapi.tx.annotation.TxTransaction;
import com.example.demo.client.Demo2Client;
import com.example.demo.client.Demo2PlusClient;
import com.example.demo.dao.TestDao;
import com.example.demo.entity.TestEntity;
import com.example.demo.service.TestService;
import com.jxzx.common.utils.PageUtils;
import com.jxzx.common.utils.QueryPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;


@Service("testService")
public class TestServiceImpl extends ServiceImpl<TestDao, TestEntity> implements TestService, ITxTransaction {
    @Autowired
    private Demo2PlusClient demo2PlusClient;
    @Autowired
    private Demo2Client demo2Client;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<TestEntity> page = this.selectPage(
                new QueryPage<TestEntity>(params).getPage(),
                new EntityWrapper<TestEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<TestEntity> list() {
        return this.baseMapper.selectList(null);
    }

    @Override
    @TxTransaction(isStart = true)
    @Transactional
    public int save() {
        TestEntity testEntity = new TestEntity();
        testEntity.setName("mybatis-plus-hello-1");
        this.baseMapper.insert(testEntity);
        demo2PlusClient.save();
//        demo2Client.save();

//        int v = 100/0;
        return 0;
    }

}
